package com.alexwan.nightnote.ui.activity;

import android.app.Activity;
import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

import com.alexwan.nightnote.R;
import com.alexwan.nightnote.db.ArticleProvider;
import com.alexwan.nightnote.db.ArticleProvider.ArticleConstants;

/**
 * 添加文章
 * 
 * @author wanhongchang
 * 
 */
public class AddArticleActivity extends Activity implements OnClickListener {

	public static void launch(Context context) {
		Intent intent = new Intent(context, AddArticleActivity.class);
		context.startActivity(intent);
	}
	//
	private EditText mArticleTitle, mArticleContent, mArticleAuthor;
	private ContentResolver mContentResolver;
	private Button mConfirmBtn;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_add_article);
		initView();

	}

	private void initView() {
		mContentResolver = this.getContentResolver();
		mArticleTitle = (EditText) findViewById(R.id.article_title);
		mArticleAuthor = (EditText) findViewById(R.id.article_author);
		mArticleContent = (EditText) findViewById(R.id.article_content);
		mConfirmBtn = (Button) findViewById(R.id.confirm_btn);
		mConfirmBtn.setOnClickListener(this);
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.confirm_btn:
			AddArticle();
			break;

		default:
			break;
		}
	}

	private void AddArticle() {
		// TODO Auto-generated method stub
		ContentValues values = new ContentValues();
		values.put(ArticleConstants.USER_NAME, "张三");
		values.put(ArticleConstants.ARTICLE_TITLE, "日记");
		values.put(ArticleConstants.ARTICLE_CONTENT, "解忧杂货店");
		values.put(ArticleConstants.ARTICLE_TIME, "2015-01-01");
		values.put(ArticleConstants.ARTICLE_PIC, "d");
		mContentResolver.insert(ArticleProvider.CONETNT_URI, values);
	}

}
